home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / hf^k-5.dms / in.adf / PhxASS.Lha / Examples / menu.asm < prev    next >
Encoding:
Assembly Source File  |  1996-10-13  |  6.9 KB  |  366 lines

  1. **
  2. **    Menu Example
  3. **
  4.  
  5.  
  6.     incdir    "include"
  7.     include    "lib/exec.i"        ; library offsets
  8.     include    "lib/intuition.i"
  9.     include    "lib/gadtools.i"
  10.  
  11. **  You should also define an include path for your Commodore **
  12. ** includes or make use of the PHXASSINC environment variable **
  13.     include    "intuition/intuition.i"
  14.     include    "libraries/gadtools.i"
  15.     include    "graphics/rastport.i"
  16.     include    "graphics/text.i"
  17.  
  18.  
  19.  
  20.     code
  21.  
  22.  
  23. start:
  24.     bsr    initialize
  25.     beq    1$            ;error during init?
  26.     bsr    main            ;main loop
  27. 1$:    bsr    cleanup            ;free all
  28.     moveq    #0,d0
  29.     rts
  30.  
  31.  
  32. main:
  33.     move.l    GadtoolsBase,a6
  34.     move.l    usrport,a0
  35.     jsr    GT_GetIMsg(a6)        ;fetch next IDCMP-Message
  36.     tst.l    d0
  37.     bne    2$            ;deal with it
  38.     move.l    SysBase,a6
  39.     move.l    usrport,a0        ;process sleeps until next
  40.     jsr    WaitPort(a6)        ; message arrives
  41.     bra    main
  42.  
  43. 2$:    move.l    d0,a1
  44.     move.l    im_Class(a1),d3        ;d2 message's IDCMP-Class
  45.     move.w    im_Code(a1),d2        ;d3 IDCMP-Code
  46.     move.l    im_IAddress(a1),a2    ;a2 object which generated this msg
  47.     jsr    GT_ReplyIMsg(a6)
  48.  
  49.     cmp.l    #IDCMP_CLOSEWINDOW,d3    ;clicked close gadget?
  50.     beq    1$
  51.  
  52.     cmp.l    #IDCMP_MENUPICK,d3    ;picked a menu item?
  53.     bne    3$
  54.     cmp.w    #MENUNULL,d2
  55.     beq    main
  56.     cmp.w    #(NOSUB<<11)|(2<<5)|0,d2 ;menu 0, item 2 : Quit ?
  57.     beq    1$
  58.     move.l    IntBase,a6
  59.     move.l    menuptr,a0
  60.     moveq    #0,d0
  61.     move.w    d2,d0
  62.     jsr    ItemAddress(a6)        ;get addr of menu item
  63.     move.l    d0,a0
  64.     moveq    #$1f,d0
  65.     and.w    d2,d0            ;d0 menu number
  66.     lsr.w    #5,d2
  67.     moveq    #$3f,d1
  68.     and.w    d3,d1            ;d1 menu item number
  69.     lsr.w    #6,d2            ;d2 menu sub item number
  70.     bsr    do_menu            ;do menu action
  71. 3$:    bra    main
  72.  
  73. 1$:    rts
  74.  
  75.  
  76. do_menu:
  77. ; Perform an action for the selected menu item
  78. ; a6 = IntuitionBase
  79. ; a0 = MenuItem address
  80. ; d0 = menu number
  81. ; d1 = menu item number
  82. ; d2 = menu sub item number
  83.     cmp.w    #0,d0            ;first nenu
  84.     bne    2$
  85.     cmp.w    #0,d1            ;and first menu item selected?
  86.     bne    2$
  87.     clr.l    -(sp)            ;user picked "About..."
  88.     move.l    winptr,a0
  89.     lea    easyreq_about,a1
  90.     move.l    sp,a2
  91.     move.l    sp,a3
  92.     jsr    EasyRequestArgs(a6)    ;display short information
  93.     addq.l    #4,sp
  94.     bra    1$
  95. 2$:    cmp.w    #1,d0            ;second menu?
  96.     bne    1$
  97.     move.l    mi_ItemFill(a0),a0    ;pointer to menu item's name
  98.     move.l    it_IText(a0),-(sp)
  99.     move.l    sp,a3            ;pass as an argument for EasyReq
  100.     clr.l    -(sp)
  101.     move.l    sp,a2
  102.     move.l    winptr,a0        ;show its name
  103.     lea    easyreq_menupick,a1
  104.     jsr    EasyRequestArgs(a6)
  105.     addq.l    #8,sp
  106. 1$:    rts
  107.  
  108.  
  109. initialize:
  110. ; open all reqiuired libraries, initialize menu and
  111. ; open a window on the workbench
  112. ; -> d0 = TRUE: ok, FALSE: error
  113.     move.l    4,a6
  114.     move.l    a6,SysBase
  115.     lea    intname(pc),a1
  116.     moveq    #36,d0
  117.     jsr    OpenLibrary(a6)        ;intuition.library v36
  118.     move.l    d0,IntBase
  119.     beq    1$
  120.     lea    gadtname(pc),a1
  121.     moveq    #36,d0
  122.     jsr    OpenLibrary(a6)        ;gadtools.library v36
  123.     move.l    d0,GadtoolsBase
  124.     beq    1$
  125.  
  126.     move.l    IntBase,a6
  127.     lea    mywindow,a0
  128.     lea    wintags(pc),a1
  129.     jsr    OpenWindowTagList(a6)    ;open a window on the workbench
  130.     move.l    d0,winptr
  131.     beq    1$
  132.     move.l    d0,a2
  133.     move.l    wd_UserPort(a2),usrport    ;pointer to windows's IDCMPMsgPort
  134.     move.l    GadtoolsBase,a6
  135.     move.l    wd_WScreen(a2),a0
  136.     sub.l    a1,a1
  137.     jsr    GetVisualInfoA(a6)    ;get pointer to VisualInfo
  138.     move.l    d0,vinfo
  139.     beq    1$
  140.     move.l    d0,d7            ;d7 VisualInfo
  141.     lea    mymenu,a0
  142.     sub.l    a1,a1            ;CreateMenus() makes a real Intu-
  143.     jsr    CreateMenusA(a6)    ; ition menu from NewMenu
  144.     move.l    d0,menuptr
  145.     beq    1$
  146.     move.l    menuptr,a0
  147.     move.l    d7,a1
  148.     lea    menutags(pc),a2
  149.     jsr    LayoutMenusA(a6)    ;arrange menus and menu entries
  150.     tst.l    d0
  151.     beq    1$
  152.     move.l    IntBase,a6
  153.     move.l    winptr,a0
  154.     move.l    menuptr,a1
  155.     jsr    SetMenuStrip(a6)    ;assign menu to window
  156.     tst.l    d0
  157.     beq    1$
  158.  
  159.     moveq    #-1,d0            ;ok, no problems
  160. 1$:    rts
  161.  
  162. wintags:
  163.     dc.l    WA_Checkmark,cmimg
  164.     dc.l    WA_NewLookMenus,1
  165.     dc.l    TAG_DONE
  166. menutags:
  167.     dc.l    GTMN_Checkmark,cmimg
  168.     dc.l    GTMN_NewLookMenus,1
  169.     dc.l    TAG_DONE
  170.  
  171.  
  172. cleanup:
  173. ; free all allocated resources
  174.     move.l    IntBase,d0
  175.     beq    1$
  176.     move.l    d0,a6
  177.     move.l    winptr,d0
  178.     beq    5$
  179.     move.l    d0,a2
  180.     tst.l    wd_MenuStrip(a2)    ;window has a menu attached?
  181.     beq    6$
  182.     move.l    a2,a0
  183.     jsr    ClearMenuStrip(a6)    ;remove menu
  184. 6$:    move.l    a2,a0
  185.     jsr    CloseWindow(a6)        ;close window
  186. 5$:    move.l    GadtoolsBase,d0
  187.     beq    2$
  188.     move.l    d0,a6
  189.     move.l    vinfo,d0
  190.     beq    4$
  191.     move.l    d0,a0
  192.     jsr    FreeVisualInfo(a6)    ;free screen's VisualInfo
  193. 4$:    move.l    menuptr,d0
  194.     beq    3$
  195.     move.l    d0,a0
  196.     jsr    FreeMenus(a6)        ;free Menu structure
  197. 3$:    move.l    SysBase,a6
  198.     move.l    GadtoolsBase,d0
  199.     beq    2$
  200.     move.l    d0,a1
  201.     jsr    CloseLibrary(a6)    ;close gadtools.library
  202. 2$:    move.l    SysBase,a6
  203.     move.l    IntBase,d0
  204.     beq    1$
  205.     move.l    d0,a1
  206.     jsr    CloseLibrary(a6)    ;close intuition.library
  207. 1$:    rts
  208.  
  209.  
  210. intname:
  211.     dc.b    "intuition.library",0
  212. gadtname:
  213.     dc.b    "gadtools.library",0
  214.  
  215.  
  216.  
  217.     data
  218.  
  219.  
  220. cmimg:                    ;new Checkmark Image (struct Image)
  221.     dc.w    0,0,15,13,2
  222.     dc.l    cmdata
  223.     dc.b    %00000011        ;plane pick
  224.     dc.b    %00000000        ;plane on/off
  225.     dc.l    0
  226.  
  227. mywindow:                ;struct NewWindow
  228.     dc.w    16,16,256,128
  229.     dc.b    0,1
  230. ; we're waiting for the following IDCMP messages
  231.     dc.l    IDCMP_CLOSEWINDOW|IDCMP_MENUPICK
  232. ; window flags
  233.     dc.l    WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET
  234.     dc.l    0,0,win_title,0,0
  235.     dc.w    128,32,-1,-1,WBENCHSCREEN
  236. win_title:
  237.     dc.b    "Menutest",0
  238.     even
  239.  
  240.  
  241. mymenu:                    ; the menu definition
  242.     dc.b    NM_TITLE,0
  243.     dc.l    menu1_name
  244.     dcb.b    14,0
  245.     dc.b    NM_ITEM,0
  246.     dc.l    m1_item1_name
  247.     dcb.b    14,0
  248.     dc.b    NM_ITEM,0
  249.     dc.l    NM_BARLABEL
  250.     dcb.b    14,0
  251.     dc.b    NM_ITEM,0
  252.     dc.l    m1_item2_name
  253.     dcb.b    14,0
  254.  
  255.     dc.b    NM_TITLE,0
  256.     dc.l    menu2_name
  257.     dcb.b    14,0
  258.     dc.b    NM_ITEM,0
  259.     dc.l    m2_item1_name
  260.     dcb.b    14,0
  261.     dc.b    NM_ITEM,0
  262.     dc.l    m2_item2_name
  263.     dcb.b    14,0
  264.     dc.b    NM_ITEM,0
  265.     dc.l    m2_item3_name
  266.     dcb.b    14,0
  267.     dc.b    NM_ITEM,0
  268.     dc.l    m2_item4_name
  269.     dcb.b    14,0
  270.  
  271.     dc.b    NM_TITLE,0
  272.     dc.l    menu3_name
  273.     dcb.b    14,0
  274.     dc.b    NM_ITEM,0
  275.     dc.l    m3_item1_name,0
  276.     dc.w    CHECKIT|MENUTOGGLE
  277.     dc.l    0,0
  278.  
  279.     dc.b    NM_END
  280.  
  281. menu1_name:
  282.     dc.b    "Project",0
  283. m1_item1_name:
  284.     dc.b    "About...",0
  285. m1_item2_name:
  286.     dc.b    "Quit",0
  287. menu2_name:
  288.     dc.b    "Test menu",0
  289. m2_item1_name:
  290.     dc.b    "This",0
  291. m2_item2_name:
  292.     dc.b    "is",0
  293. m2_item3_name:
  294.     dc.b    "a",0
  295. m2_item4_name:
  296.     dc.b    "test",0
  297. menu3_name:
  298.     dc.b    "Checkmark",0
  299. m3_item1_name:
  300.     dc.b    "Toggle",0
  301.     even
  302.  
  303. easyreq_about:    ;EasyRequester, refer to intuition/intuition.i
  304.     dc.l    EasyStruct_SIZEOF,0,1$,2$,3$
  305. 1$:    dc.b    "About this program...",0
  306. 2$:    dc.b    "This is an example for\n"
  307.     dc.b    "programming menus.",0
  308. 3$:    dc.b    "Ok|Indeed|So what?",0
  309.     even
  310.  
  311. easyreq_menupick:
  312.     dc.l    EasyStruct_SIZEOF,0,1$,2$,3$
  313. 1$:    dc.b    "A Menu item was picked!",0
  314. 2$:    dc.b    "The user selected the menu\n"
  315.     dc.b    "item named \"%s\".",0
  316. 3$:    dc.b    "Yes",0
  317.     even
  318.  
  319.  
  320.  
  321.     bss
  322.  
  323.  
  324. SysBase:    ds.l    1
  325. IntBase:    ds.l    1
  326. GadtoolsBase:    ds.l    1
  327. menuptr:    ds.l    1
  328. winptr:        ds.l    1
  329. usrport:    ds.l    1
  330. vinfo:        ds.l    1
  331.  
  332.  
  333.  
  334.     section    ImageData,data,chip
  335.  
  336. cmdata:
  337.     dc.w    %0000011111000000
  338.     dc.w    %0001111111110000
  339.     dc.w    %0011111111111000
  340.     dc.w    %0111111111111100
  341.     dc.w    %1111111111111110
  342.     dc.w    %1111111111111110
  343.     dc.w    %1111111111111110
  344.     dc.w    %1111111111111110
  345.     dc.w    %1111111111111110
  346.     dc.w    %0111111111111100
  347.     dc.w    %0011111111111000
  348.     dc.w    %0001111111110000
  349.     dc.w    %0000011111000000
  350.     dc.w    %1111100000111111
  351.     dc.w    %1110000000001111
  352.     dc.w    %1100000000000111
  353.     dc.w    %1000000000000011
  354.     dc.w    %0000000000000001
  355.     dc.w    %0000000000000001
  356.     dc.w    %0000000000000001
  357.     dc.w    %0000000000000001
  358.     dc.w    %0000000000000001
  359.     dc.w    %1000000000000011
  360.     dc.w    %1100000000000111
  361.     dc.w    %1110000000001111
  362.     dc.w    %1111100000111111
  363.  
  364.  
  365.     end
  366.